using System.Collections;
using System.Collections.Generic;
using Cysharp.Threading.Tasks;
using UnityEngine;


//WhenAll �ȴ����� ȫ������ִ��

public class Three : MonoBehaviour
{
    public GameObject ball1;
    public GameObject ball2;
    void Start()
    {
        TestWhenAll();
    }

    // Update is called once per frame
    void Update()
    {
        ball1.transform.Translate(new Vector3(1, 0, 0) * Time.deltaTime);
        ball2.transform.Translate(new Vector3(1, 0, 0) * Time.deltaTime*0.5f);
    }


    
    async void TestWhenAll()
    {
        // 相当于监听 条件满足时执行|返回
        UniTask task1 = UniTask.WaitUntil(() => ball1.transform.position.x > 1);
        UniTask task2 = UniTask.WaitUntil(() => ball2.transform.position.x > 1);
        // 等待条件满足才执行,全都到达完成状态?
        await UniTask.WhenAll(task1, task2);

        string str = $"ball1:{ball1.transform.position.x},ball2:{ball2.transform.position.x}";
        Debug.Log(str);
    }
}
